package com.han.interpreter;

/**
 * @ClassName Client
 * @Description 描述该类的功能
 * @Author duoduo Han
 * @Date 2024/6/23 11:40
 */
public class Client {
    public static void main(String[] args) {
        //创建环境对象
        Context context = new Context();
        //创建多个变量对象
        Variable a = new Variable("a");
        Variable b = new Variable("b");
        Variable c = new Variable("c");
        Variable d = new Variable("d");

        //将变量存储道环境对象中
        context.assign(a, 10);
        context.assign(b, 20);
        context.assign(c, 30);
        context.assign(d, 40);

        //获取抽象语法树
        AbstractExpression expression = new Minus(a, new Plus(new Minus(b, c), d));

        //解释（计算）
        int res = expression.interpret(context);
        System.out.println(expression + "=" + res);

    }
}
